print("----------------------------------xxtea_test")

--local codec = require('codec')
--local src, key = '123456', '01234567890abcdef'
--local bs = codec.aes_encrypt(src, key)
--local dst = codec.base64_encode(bs)
--print(dst)
--
--local dbs = codec.base64_decode(dst)
--local dsrc = codec.aes_decrypt(dbs, key)
--print(dsrc)
--
--assert(dsrc == src)

local xxtea  = require("libxxtea")
--print("111111", type(xxtea))
-- key
local key = '0123456789'
--local x = xxtea()
--x:init(key)


local luacrypto = require("luacrypto")
local base64 = luacrypto.base64.new()
--local str4 = base64:Encode(encrypted_data)
--print("base64 -> " .. str4)

-- 加密
local data = '{\"cd_time\":0,\"status\":5,\"all_time\":10,\"curr_seatid\":0,\"balls\":[{\"pos_x\":\"610.0\",\"goin\":0,\"pos_y\":\"250.0\",\"vel_y\":\"0\",\"vel_x\":\"0\",\"tag\":1},{\"pos_x\":\"633.255106966\",\"goin\":0,\"pos_y\":\"236.3\",\"vel_y\":\"0\",\"vel_x\":\"0\",\"tag\":2},{\"pos_x\":\"633.255106966\",\"goin\":0,\"pos_y\":\"263.7\",\"vel_y\":\"0\",\"vel_x\":\"0\",\"tag\":3},{\"pos_x\":\"656.510213932\",\"goin\":0,\"pos_y\":\"222.6\",\"vel_y\":\"0\",\"vel_x\":\"0\",\"tag\":4},{\"pos_x\":\"656.510213932\",\"goin\":0,\"pos_y\":\"250.0\",\"vel_y\":\"0\",\"vel_x\":\"0\",\"tag\":5},{\"pos_x\":\"656.510213932\",\"goin\":0,\"pos_y\":\"277.4\",\"vel_y\":\"0\",\"vel_x\":\"0\",\"tag\":6},{\"pos_x\":\"679.76532089799\",\"goin\":0,\"pos_y\":\"208.9\",\"vel_y\":\"0\",\"vel_x\":\"0\",\"tag\":7},{\"pos_x\":\"679.76532089799\",\"goin\":0,\"pos_y\":\"236.3\",\"vel_y\":\"0\",\"vel_x\":\"0\",\"tag\":8},{\"pos_x\":\"679.76532089799\",\"goin\":0,\"pos_y\":\"263.7\",\"vel_y\":\"0\",\"vel_x\":\"0\",\"tag\":9},{\"pos_x\":\"679.76532089799\",\"goin\":0,\"pos_y\":\"291.1\",\"vel_y\":\"0\",\"vel_x\":\"0\",\"tag\":10},{\"pos_x\":\"703.02042786399\",\"goin\":0,\"pos_y\":\"195.2\",\"vel_y\":\"0\",\"vel_x\":\"0\",\"tag\":11},{\"pos_x\":\"703.02042786399\",\"goin\":0,\"pos_y\":\"222.6\",\"vel_y\":\"0\",\"vel_x\":\"0\",\"tag\":12},{\"pos_x\":\"703.02042786399\",\"goin\":0,\"pos_y\":\"250.0\",\"vel_y\":\"0\",\"vel_x\":\"0\",\"tag\":13},{\"pos_x\":\"703.02042786399\",\"goin\":0,\"pos_y\":\"277.4\",\"vel_y\":\"0\",\"vel_x\":\"0\",\"tag\":14},{\"pos_x\":\"703.02042786399\",\"goin\":0,\"pos_y\":\"304.8\",\"vel_y\":\"0\",\"vel_x\":\"0\",\"tag\":15},{\"pos_x\":\"180\",\"goin\":0,\"pos_y\":\"350\",\"vel_y\":\"0\",\"vel_x\":\"0\",\"tag\":16},{\"pos_x\":\"180\",\"goin\":0,\"pos_y\":\"150\",\"vel_y\":\"0\",\"vel_x\":\"0\",\"tag\":17},{\"pos_x\":\"180\",\"goin\":0,\"pos_y\":\"250\",\"vel_y\":\"0\",\"vel_x\":\"0\",\"tag\":18},{\"pos_x\":\"400\",\"goin\":0,\"pos_y\":\"250\",\"vel_y\":\"0\",\"vel_x\":\"0\",\"tag\":19},{\"pos_x\":\"581\",\"goin\":0,\"pos_y\":\"250\",\"vel_y\":\"0\",\"vel_x\":\"0\",\"tag\":20},{\"pos_x\":\"740\",\"goin\":0,\"pos_y\":\"250\",\"vel_y\":\"0\",\"vel_x\":\"0\",\"tag\":21},{\"pos_x\":\"100\",\"goin\":0,\"pos_y\":\"200\",\"vel_y\":\"0\",\"vel_x\":\"0\",\"tag\":22}],\"rid\":1,\"tid\":\"0_1_101_2_1684465398\",\"self_user\":{\"mid\":100,\"seatid\":0},\"seats\":{}}'
--local data = "hello"
--data =  base64:Encode(data)
--print("data:", data)
local encrypted_data = xxtea.encrypt(data, string.len(data), key)
local bd =  base64:Encode(encrypted_data)
print(bd)
print("\n")

print("\n")
--print(base64:Encode("hello"))
local data_len = string.len(encrypted_data)
-- 解密
local decrypted_data = xxtea.decrypt(encrypted_data, data_len, key)


--decrypted_data =  base64:Decode(decrypted_data)

print(decrypted_data)
print("------------------------end")